#include <device.h>
#define maxRotation 8000
#define konstant 100

// Proto typer
void Psoc5Init(); // Initalizerings funktion

void main()
{

	Psoc5Init();
    for(;;)
    {
		temperatur_ = 0x10;//temperatur();
		batteriSpaending_ = 0x20;//batteriSpaending();
		ladestroem_ = 0x30;//ladestroem();
		if((SPIS_1_ReadRxStatus() & SPIS_1_STS_RX_FIFO_NOT_EMPTY) != 0)
		{
			//SPIFlag = 0;
			SPI_send(temperatur_, batteriSpaending_, ladestroem_);
		}
		if(TimerISR && (position_ < maxRotation) && ( RTC_1_ReadHour() > 18) && (RTC_1_ReadHour() < 6) )
		{
			lys_ = lysfoeler();
			steps_ = lys_/konstant;
			position_ = stepFull(steps_,100, 1);
			TimerISR = 0;
		}
		if(position_ >= maxRotation)
		{
			steps_ = -position_;
		}
	}
		
}

void Psoc5Init()
{
	temperatur_ = 0;
	batteriSpaending_ = 0;
	ladestroem_ = 0;
	ADC_DelSig_1_Start();
	ADC_DelSig_1_IRQ_Disable();
	Opamp_1_Start();
	Opamp_2_Start();
	AMux_1_Start();
	AMux_2_Start();
	RTC_1_Start();
	RTC_1_EnableInt();
	initSPI();

}